home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / mib / mibload.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-10  |  19.2 KB  |  767 lines

  1. #include "mibload.h"
  2. #include "mibwidgets.h"
  3.  
  4. mib_Widget    *mib_root_Widget;
  5. Display        *dpy;
  6. GC         mib_gc;
  7. static struct _mib_event_handle_funcs {
  8.   void        (*mib_pick_mib_Widget)(/* Widget, XtPointer,
  9.             XButtonPressedEvent *, Boolean * */);
  10.   void        (*mib_move_mib_Widget)(/* Widget, XtPointer,
  11.             XPointerMovedEvent *, Boolean * */);
  12.   void        (*mib_unpick_mib_Widget)(/* Widget, XtPointer,
  13.             XButtonReleasedEvent *, Boolean * */);
  14. } mib_events;
  15.  
  16. mib_widget_funcs mwfuncs[] =
  17. {
  18.   { NULL, NULL, NULL, NULL, NULL },
  19.   { "TextBox", mib_create_TextBox, mib_delete_TextBox,
  20.     mib_save_TextBox, mib_load_TextBox},
  21.   { "Button", mib_create_Button, mib_delete_Button,
  22.     mib_save_Button, mib_load_Button},
  23.   { "Toggle", mib_create_Toggle, mib_delete_Toggle,
  24.     mib_save_Toggle, mib_load_Toggle},
  25.   { "RadioBox", mib_create_RadioBox, mib_delete_RadioBox,
  26.     mib_save_RadioBox, mib_load_RadioBox},
  27.   { "DrawingArea", mib_create_DrawingArea, mib_delete_DrawingArea,
  28.     mib_save_DrawingArea, mib_load_DrawingArea},
  29.   { "Label", mib_create_Label, mib_delete_Label,
  30.     mib_save_Label, mib_load_Label},
  31.   { "Frame", mib_create_Frame, mib_delete_Frame,
  32.     mib_save_Frame, mib_load_Frame},
  33.   { "ScrollBar", mib_create_ScrollBar, mib_delete_ScrollBar,
  34.     mib_save_ScrollBar, mib_load_ScrollBar},
  35.   { "TextBig", mib_create_TextBig, mib_delete_TextBig,
  36.     mib_save_TextBig, mib_load_TextBig},
  37.   { "List", mib_create_List, mib_delete_List,
  38.     mib_save_List, mib_load_List},
  39.   { "Scale", mib_create_Scale, mib_delete_Scale,
  40.     mib_save_Scale, mib_load_Scale},
  41.   { "Menu", mib_create_Menu, mib_delete_Menu,
  42.     mib_save_Menu, mib_load_Menu},
  43.   { NULL, NULL, NULL, NULL, NULL },
  44. };
  45.  
  46. /*****************************************************************************/
  47.  
  48. void mib_add_mib_Widget(mib_Widget *this, mib_Widget *parent)
  49. {
  50.   mib_Widget *tmp;
  51.  
  52.   if (parent->child == NULL)
  53.   {
  54.     parent->child = this;
  55.     this->prev = parent;
  56.     this->parent = parent;
  57.     this->sibling = NULL;
  58.     this->child = NULL;
  59.   }
  60.   else
  61.     {
  62.       tmp = parent->child;
  63.       while (tmp->sibling != NULL)
  64.         tmp = tmp->sibling;
  65.       tmp->sibling = this;
  66.       this->prev = tmp;
  67.       this->parent = parent;
  68.       this->sibling = NULL;
  69.       this->child = NULL;
  70.     }
  71. }
  72.  
  73. /*****************************************************************************/
  74.  
  75. void mib_add_backward(mib_Widget *this, mib_Widget *parent)
  76. {
  77.   mib_Widget *tmp;
  78.  
  79.   if (parent->child == NULL)
  80.   {
  81.     parent->child = this;
  82.     this->prev = parent;
  83.     this->parent = parent;
  84.     this->sibling = NULL;
  85.     this->child = NULL;
  86.   }
  87.   else
  88.     {
  89.       tmp = parent->child;
  90.       parent->child = this;
  91.       this->prev = parent;
  92.       this->parent = parent;
  93.       this->sibling = tmp;
  94.       this->child = NULL;
  95.       tmp->prev = this;
  96.     }
  97. }
  98.  
  99. /*****************************************************************************/
  100.  
  101. void mib_remove_mib_Widget(mib_Widget *this)
  102. {
  103.   int         count;
  104.   mib_Widget    *pnt;
  105.  
  106.   XtVaSetValues(mib_root_Widget->me, XmNresizePolicy, XmRESIZE_NONE, NULL);
  107.   XtDestroyWidget(this->me);
  108.  
  109.   while (this->child != NULL)
  110.     mib_remove_mib_Widget(this->child);
  111.  
  112.   if (this->parent == this)
  113.   {
  114.     mib_clear_myres(this);
  115.     return;
  116.   }
  117.  
  118.   if (this->prev == this->parent)
  119.   {
  120.     this->parent->child = this->sibling;
  121.     if (this->sibling != NULL)
  122.       this->sibling->prev = this->parent;
  123.   }
  124.   else
  125.     {
  126.       this->prev->sibling = this->sibling;
  127.       if (this->sibling != NULL)
  128.     this->sibling->prev = this->prev;
  129.     }
  130.  
  131.   mib_clear_myres(this);
  132. }
  133.  
  134. /*****************************************************************************/
  135.  
  136. void mib_clear_myres(mib_Widget *this)
  137. {
  138.   free(this->mib_class);
  139.   free(this->name);
  140.  
  141.   if ((this->mib_class_num < 1) || (this->mib_class_num > MI_NUMCLASSES))
  142.     return;
  143.  
  144.   mwfuncs[this->mib_class_num].mib_delete(this);
  145.   free(this);
  146. }
  147.  
  148. /*****************************************************************************/
  149.  
  150. mib_Widget *mib_new_mib_Widget()
  151. {
  152.   mib_Widget *this;
  153.   this = (mib_Widget *)malloc(sizeof(mib_Widget));
  154.   this->me = NULL;
  155.   this->mib_class_num = MIB_NULL;
  156.   this->mib_selected = 0;
  157.   this->mib_resizing = 0;
  158.   this->myres = NULL;
  159.   this->parent = NULL;
  160.   this->sibling = NULL;
  161.   this->prev = NULL;
  162.   this->child = NULL;
  163.   this->width = 0;
  164.   this->height = 0;
  165.   this->topAttachment = 0;
  166.   this->bottomAttachment = 0;
  167.   this->leftAttachment = 0;
  168.   this->rightAttachment = 0;
  169.   this->topOffset = 0;
  170.   this->bottomOffset = 0;
  171.   this->leftOffset = 0;
  172.   this->rightOffset = 0;
  173.  
  174.   return this;
  175. }
  176.  
  177. /*****************************************************************************/
  178.  
  179. mib_Widget *mib_find_name(mib_Widget *temp, char *name)
  180. {
  181.   mib_Widget *child = temp->child;
  182.   mib_Widget *ret = NULL;
  183.  
  184.   if (!strcmp(temp->name, name))
  185.     return temp;
  186.  
  187.   if (child != NULL)
  188.     if (ret = mib_find_name(child, name))
  189.     return ret;
  190.  
  191.   child = temp->sibling;
  192.   if (child != NULL)
  193.     if (ret = mib_find_name(child, name))
  194.     return ret;
  195.  
  196.   return NULL;
  197. }
  198.  
  199. /*****************************************************************************/
  200.  
  201. Widget
  202. BuildMenu(Widget parent, int menu_type, char *menu_title, char menu_mnemonic,
  203.          MenuItem *items)
  204. {
  205.     Widget menu, cascade, widget;
  206.     int i;
  207.     XmString str;
  208.  
  209.     if (menu_type == XmMENU_PULLDOWN || menu_type == XmMENU_OPTION)
  210.         menu = XmCreatePulldownMenu(parent, "_pulldown", NULL, 0);
  211.     else if (menu_type == XmMENU_POPUP)
  212.         menu = XmCreatePopupMenu(parent, "_popup", NULL, 0);
  213.     else {
  214.         XtWarning("Invalid menu type passed to BuildMenu()");
  215.         return NULL;
  216.     }
  217.  
  218.     /* Pulldown menus require a cascade button to be made */
  219.     if (menu_type == XmMENU_PULLDOWN) {
  220.         str = XmStringCreateSimple(menu_title);
  221.         cascade = XtVaCreateManagedWidget(menu_title,
  222.             xmCascadeButtonGadgetClass, parent,
  223.             XmNsubMenuId,   menu,
  224.             XmNlabelString, str,
  225.             XmNmnemonic,    menu_mnemonic,
  226.             NULL);
  227.         XmStringFree(str);
  228.     } else if (menu_type == XmMENU_OPTION) {
  229.         /* Option menus are a special case, but not hard to handle */
  230.         Arg args[2];
  231.         str = XmStringCreateSimple(menu_title);
  232.         XtSetArg(args[0], XmNsubMenuId, menu);
  233.         XtSetArg(args[1], XmNlabelString, str);
  234.         /* This really isn't a cascade, but this is the widget handle
  235.          * we're going to return at the end of the function.
  236.          */
  237.         cascade = XmCreateOptionMenu(parent, menu_title, args, 2);
  238.         XmStringFree(str);
  239.     }
  240.  
  241.     /* Now add the menu items */
  242.     for (i = 0; items[i].label != NULL; i++) {
  243.         /* If subitems exist, create the pull-right menu by calling this
  244.          * function recursively.  Since the function returns a cascade
  245.          * button, the widget returned is used..
  246.          */
  247.         if (items[i].subitems)
  248.             if (menu_type == XmMENU_OPTION) {
  249.             widget = XtVaCreateManagedWidget(items[i].label,
  250.                 *items[i].class, menu, NULL);
  251.         items[i].subitems = (struct _menu_item *) widget;
  252.          /* daeron mod (tm) :-) ... we now use this to pass back each
  253.         widget we create to the mibMenu functions so that it can
  254.         be stored as part of the mibMenu structure */
  255.  
  256.              /* XtWarning("You can't have submenus from option menu items.");
  257.                 continue;*/
  258.             } else
  259.                 widget = BuildMenu(menu, XmMENU_PULLDOWN,
  260.                     items[i].label, items[i].mnemonic, items[i].subitems);
  261.         else
  262.       {
  263.             widget = XtVaCreateManagedWidget(items[i].label,
  264.                 *items[i].class, menu,
  265.                 NULL);
  266.         /* ditto here from above ... - Daeron mod (tm) */
  267.         items[i].subitems = (struct _menu_item *) widget;
  268.       }
  269.  
  270.         /* Whether the item is a real item or a cascade button with a
  271.          * menu, it can still have a mnemonic.
  272.          */
  273.         if (items[i].mnemonic)
  274.             XtVaSetValues(widget, XmNmnemonic, items[i].mnemonic, NULL);
  275.  
  276.         /* any item can have an accelerator, except cascade menus. But,
  277.          * we don't worry about that; we know better in our declarations.
  278.          */
  279.         if (items[i].accelerator) {
  280.             str = XmStringCreateSimple(items[i].accel_text);
  281.             XtVaSetValues(widget,
  282.                 XmNaccelerator, items[i].accelerator,
  283.                 XmNacceleratorText, str,
  284.                 NULL);
  285.             XmStringFree(str);
  286.         }
  287.  
  288.         if (items[i].callback)
  289.             XtAddCallback(widget,
  290.                 (items[i].class == &xmToggleButtonWidgetClass ||
  291.                  items[i].class == &xmToggleButtonGadgetClass)?
  292.                     XmNvalueChangedCallback : /* ToggleButton class */
  293.                     XmNactivateCallback,      /* PushButton class */
  294.                 items[i].callback, items[i].callback_data);
  295.     }
  296.  
  297.     /* for popup menus, just return the menu; pulldown menus, return
  298.      * the cascade button; option menus, return the thing returned
  299.      * from XmCreateOptionMenu().  This isn't a menu, or a cascade button!
  300.      */
  301.     return menu_type == XmMENU_POPUP? menu : cascade;
  302. }
  303.  
  304. /*****************************************************************************/
  305.  
  306. mib_Widget *mib_load_interface(Widget parent, char *from, int file_type)
  307. {
  308.   mib_Buffer  thisfile;
  309.   mib_Widget *this;
  310.   FILE         *infile;
  311.   char         *instring;
  312.   char          ch;
  313.  
  314.   thisfile.buf_type = file_type;
  315.  
  316.   dpy = XtDisplay(parent);
  317.  
  318.   if ((file_type == MI_FROMFILE) || (file_type == MI_EDITFROMFILE))
  319.   {
  320.     if (!(infile = fopen(from,"r")))
  321.       return NULL;
  322.  
  323.     ch = '\0';
  324.     while ((ch != '\n')&&(!feof(infile)))  /* throw away first line */
  325.       ch = (char)fgetc(infile);
  326.  
  327.     thisfile.buffer = (void *)infile;
  328.     thisfile.point = 0;
  329.  
  330.     if (!mib_load_Root(parent, &this, &thisfile))
  331.     {
  332.       /* delete this */
  333.       return NULL;
  334.     }
  335.     else
  336.     {
  337.       fclose(infile);
  338.       return this;
  339.     }
  340.   }
  341.   else
  342.   if ((file_type == MI_FROMSTRING) || (file_type == MI_EDITFROMSTRING))
  343.   {
  344.     instring = from;
  345.     if (instring == NULL)
  346.       return NULL;
  347.  
  348.     thisfile.buffer = (void *)instring;
  349.     thisfile.buflen = strlen(instring);
  350.     thisfile.point = 0;
  351.  
  352.     if (!mib_load_Root(parent, &this, &thisfile))
  353.     {
  354.       /* delete this */
  355.       return NULL;
  356.     }
  357.     else
  358.       return this;
  359.   }
  360.   else
  361.     return NULL;
  362.  
  363. }
  364.  
  365. /*****************************************************************************/
  366.  
  367. int mib_load_mib_class(mib_Widget **this, mib_Widget *parent, char *name,
  368.         char *iname, mib_Buffer *fin )
  369. {
  370.   int namelen, editstate, count, set;
  371.  
  372.   if ((fin->buf_type == MI_EDITFROMFILE) ||
  373.     (fin->buf_type == MI_EDITFROMSTRING))
  374.     editstate = WEDIT;
  375.   else
  376.     editstate = WEMPTY;
  377.  
  378.   namelen = strlen(name);
  379.   if (namelen < 2)
  380.     return 0;
  381.  
  382.   name[namelen-1] = '\0';
  383.   name[0] = ' ';
  384.  
  385.   count = 1;
  386.  
  387.   while (mwfuncs[count].name)
  388.   {
  389.     if (!strcmp(&(name[1]), mwfuncs[count].name))
  390.     {
  391.       *this = mwfuncs[count].mib_create(parent, iname, NULL, 0, 0, 0, 0,
  392.         editstate);
  393.       return 1;
  394.     }
  395.     count++;
  396.   }
  397.  
  398.   (*this)->parent = (*this);
  399.   return 1;
  400. }
  401.  
  402. /*****************************************************************************/
  403.  
  404. mib_Widget *mib_load_public(mib_Widget *root, mib_Widget *this, mib_Buffer *fin)
  405. {
  406.   int    got_line, done;
  407.   char    res[MI_MAXSTRLEN];
  408.   char    val[MI_MAXSTRLEN];
  409.   char    valcp[MI_MAXSTRLEN];
  410.   Arg    args[20];
  411.   int    mynum, n;
  412.  
  413.   got_line = 1;
  414.   done = 0;
  415.  
  416.   /* this loop reads basic info about Widget */
  417.   while (got_line && (!done))
  418.   {
  419.     got_line = mib_read_line(fin, res, val);
  420.     if (!strcmp(res,"Ref"))
  421.       sscanf(val, "%d", &mynum);
  422.     else
  423.     if (!strcmp(res,"Widget"))
  424.     {
  425.       strcpy(valcp,val);
  426.       done = 1;
  427.     }
  428.   }
  429.  
  430.   done = 0;
  431.  
  432.   while (got_line && (!done))
  433.   {
  434.     got_line = mib_read_line(fin, res, val);
  435.     if (!strcmp(res, "Children"))
  436.       n = 0;
  437.     else
  438.     if (!strcmp(res, "Parent")) /* don't support complete widget tree yet */
  439.       n = 0;
  440.     else
  441.     if (!strcmp(res,"Public-"))
  442.       n = 0;
  443.     else
  444.     if (!strcmp(res,"Name"))
  445.     {
  446.       val[strlen(val)-1] = '\0';
  447.       mib_load_mib_class(&this, root, valcp, &(val[1]), fin);
  448.       this->name = (char *)malloc(strlen(val));
  449.       sprintf(this->name,"%s",&(val[1]));
  450.       this->mib_mynum = mynum;
  451.       done = 1;
  452.     }
  453.     else
  454.        return 0;
  455.   }
  456.  
  457.   if (!got_line)
  458.     return NULL;
  459.  
  460.   done = 0;
  461.  
  462.   /* second loop reads public info */
  463.   while (got_line && (!done))
  464.   {
  465.     got_line = mib_read_line(fin, res, val);
  466.     if (!strcmp(res,"Xmwidth"))
  467.       sscanf(val,"%d",&(this->width));
  468.     else
  469.     if (!strcmp(res,"Xmheight"))
  470.       sscanf(val,"%d",&(this->height));
  471.     else
  472.     if (!strcmp(res,"XmtopAttachment"))
  473.       sscanf(val,"%d",&(this->topAttachment));
  474.     else
  475.     if (!strcmp(res,"XmbottomAttachment"))
  476.       sscanf(val,"%d",&(this->bottomAttachment));
  477.     else
  478.     if (!strcmp(res,"XmleftAttachment"))
  479.       sscanf(val,"%d",&(this->leftAttachment));
  480.     else
  481.     if (!strcmp(res,"XmrightAttachment"))
  482.       sscanf(val,"%d",&(this->rightAttachment));
  483.     else
  484.     if (!strcmp(res,"XmtopOffset"))
  485.       sscanf(val,"%d",&(this->topOffset));
  486.     else
  487.     if (!strcmp(res,"XmbottomOffset"))
  488.       sscanf(val,"%d",&(this->bottomOffset));
  489.     else
  490.     if (!strcmp(res,"XmleftOffset"))
  491.       sscanf(val,"%d",&(this->leftOffset));
  492.     else
  493.     if (!strcmp(res,"XmrightOffset"))
  494.       sscanf(val,"%d",&(this->rightOffset));
  495.     else
  496.     if (!strcmp(res,"Private-"))
  497.       done = 1;
  498.   }
  499.  
  500.   n = 0;
  501.   if ((fin->buf_type == MI_EDITFROMFILE) ||
  502.     (fin->buf_type == MI_EDITFROMSTRING))
  503.   {
  504.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  505.     XtSetArg (args[n], XmNleftOffset, this->leftOffset); n++;
  506.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  507.     XtSetArg (args[n], XmNtopOffset, this->topOffset); n++;
  508.     if (this == root)
  509.     {
  510.       XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  511.       XtSetArg (args[n], XmNrightOffset, this->rightOffset); n++;
  512.       XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  513.       XtSetArg (args[n], XmNbottomOffset, this->bottomOffset); n++;
  514.     }
  515.   }
  516.   else
  517.   {
  518.     if (this->leftAttachment)
  519.     {
  520.       XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  521.       XtSetArg (args[n], XmNleftOffset, this->leftOffset);n++;
  522.     }
  523.     if (this->topAttachment)
  524.     {
  525.       XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  526.       XtSetArg (args[n], XmNtopOffset, this->topOffset);n++;
  527.     }
  528.     if (this->bottomAttachment)
  529.     {
  530.       XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  531.       XtSetArg (args[n], XmNbottomOffset, this->bottomOffset);n++;
  532.     }
  533.     if (this->rightAttachment)
  534.     {
  535.       XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  536.       XtSetArg (args[n], XmNrightOffset, this->rightOffset);n++;
  537.     }
  538.   }
  539.  
  540.   XtSetArg (args[n], XmNwidth, this->width); n++;
  541.   XtSetArg (args[n], XmNheight, this->height); n++;
  542.  
  543.   XtSetValues(this->me, args, n);
  544.  
  545.   return this;
  546. }
  547.  
  548. /*****************************************************************************/
  549.  
  550. int mib_load_private(mib_Widget *this, mib_Buffer *fin)
  551. {
  552.  
  553.   if (this->mib_class_num == MIB_NULL)
  554.     return 1;
  555.  
  556.   if ((this->mib_class_num < 1) || (this->mib_class_num > MI_NUMCLASSES))
  557.     return 0;
  558.  
  559.   mwfuncs[this->mib_class_num].mib_load(this, fin);
  560.  
  561.   return 1;
  562. }
  563.  
  564. /*****************************************************************************/
  565.  
  566. int mib_load_Root(Widget parent, mib_Widget **this, mib_Buffer *fin)
  567. {
  568.  
  569.   char        res[MI_MAXSTRLEN];
  570.   char        val[MI_MAXSTRLEN];
  571.   char        name[MI_MAXSTRLEN];
  572.   int        num_widgets, count, n, got_line;
  573.   Arg        args[20];
  574.   XGCValues     gcvals;
  575.   XtGCMask      val_mask;
  576.   mib_Widget   *temp;
  577.  
  578.   got_line = mib_read_line(fin, res, val);
  579.   if (!strcmp(res,"TotalWidgets"))
  580.     sscanf(val, "%d", &num_widgets);
  581.   else
  582.     return 0;
  583.  
  584.   (*this) = mib_new_mib_Widget();
  585.   (*this)->mib_class = (char*)malloc(9);
  586.   sprintf((*this)->mib_class,"RootForm");
  587.  
  588.   (*this)->me = XmCreateForm(parent, "MainForm", args, 0);
  589.   if (!mib_load_public((*this), (*this), fin))
  590.     return 0;
  591.  
  592.   /* we don't expect any private resources for the root widget */
  593.  
  594.   got_line = mib_read_line(fin, res, val);
  595.   if (strcmp(res,"EndWidget."))
  596.     return 0;
  597.  
  598.   XtManageChild((*this)->me);
  599.   XtVaSetValues((*this)->me, XmNresizePolicy, XmRESIZE_NONE, NULL);
  600.  
  601.   count = num_widgets - 1;
  602.   while (count > 0)
  603.   {
  604.  
  605.     if (!(temp = mib_load_public((*this), temp, fin)))
  606.     {
  607.       /* delete temp */
  608.       return 0;
  609.     }
  610.  
  611.     if (!mib_load_private(temp,fin))
  612.     {
  613.       /* delete temp */
  614.       return 0;
  615.     }
  616.     count--;
  617.  
  618.   }
  619.  
  620.   mib_reset_size((*this));
  621.  
  622.   XtVaSetValues((*this)->me, XmNresizePolicy, XmRESIZE_ANY, NULL);
  623.  
  624.   val_mask = (long)0;
  625.   mib_gc = XtGetGC((*this)->me, val_mask, &gcvals);
  626.  
  627.   return 1;
  628. }
  629.  
  630. /*****************************************************************************/
  631.  
  632. int mib_read_line(mib_Buffer *bufin, char *res, char *val)
  633. {
  634.   FILE *fin;
  635.   char *strin;
  636.   char  ch;
  637.   int   count, mark;
  638.   char  inbuf[MI_MAXSTRLEN];
  639.  
  640.   if ((bufin->buf_type == MI_FROMFILE) || (bufin->buf_type == MI_EDITFROMFILE))
  641.   {
  642.     fin = (FILE *)bufin->buffer;
  643.     ch = '\0';
  644.     count = 0;
  645.     mark = 0;
  646.     while ((ch != '\n')&&(!feof(fin))&&(count<MI_MAXSTRLEN))
  647.     {
  648.       ch = (char)fgetc(fin);
  649.       if ((mark == 0) && (ch == ':'))
  650.     mark = count;
  651.       if ((ch != '\\')&&(ch != '\n'))
  652.       {
  653.     inbuf[count] = ch;
  654.     count++;
  655.       }
  656.     }
  657.     if (feof(fin))
  658.       return 0;
  659.     inbuf[count] = '\0';
  660.     if (count > 0)
  661.     {
  662.       if (inbuf[count-1] == 'n')
  663.         inbuf[count-1] = '\0';
  664.     }
  665.     else
  666.       return 0;
  667.  
  668.   }
  669.   else
  670.   if ((bufin->buf_type == MI_FROMSTRING) ||
  671.     (bufin->buf_type == MI_EDITFROMSTRING))
  672.   {
  673.     strin = (char *)bufin->buffer;
  674.     count = bufin->point;
  675.     mark = 0;
  676.  
  677.     if (count >= bufin->buflen)
  678.       return 0;
  679.  
  680.     while ((strin[count] != '\n') && (count < bufin->buflen))
  681.     {
  682.       if ((mark == 0) && (strin[count] == ':'))
  683.     mark = count;
  684.       count++;
  685.     }
  686.  
  687.     strin[count] = '\0';
  688.     if (count >= bufin->buflen)
  689.       return 0;
  690.     sprintf(inbuf,"%s",&(strin[bufin->point]));
  691.     strin[count] = '\n';
  692.     if (mark != 0)
  693.       mark -= bufin->point;
  694.     bufin->point = count+1;
  695.   }
  696.   else
  697.     return 0;
  698.  
  699.   if (mark == 0)
  700.   {
  701.     sprintf(res,"%s",inbuf);
  702.     sprintf(val,"\0");
  703.   }
  704.   else
  705.   {
  706.     inbuf[mark] = '\0';
  707.     sprintf(res,"%s",inbuf);
  708.     inbuf[mark] = ' ';
  709.     if (strlen(inbuf)-mark > 1)
  710.       sprintf(val,"%s",&(inbuf[mark+2]));
  711.     else
  712.       sprintf(val,"\0");
  713.   }
  714.  
  715.   return 1;
  716. }
  717.  
  718. /*****************************************************************************/
  719.  
  720. void mib_reset_size(mib_Widget *temp)
  721. {
  722.   Arg    args[5];
  723.   int    n;
  724.  
  725.   mib_Widget *child = temp->child;
  726.  
  727.   if (temp->mib_class_num != MIB_NULL)
  728.   {
  729.     n = 0;
  730.     XtSetArg (args[n], XmNwidth, temp->width); n++;
  731.     XtSetArg (args[n], XmNheight, temp->height); n++;
  732.  
  733.     XtSetValues(temp->me, args, n);
  734.   }
  735.  
  736.   if (child != NULL)
  737.     mib_reset_size(child);
  738.  
  739.   child = temp->sibling;
  740.   if (child != NULL)
  741.     mib_reset_size(child);
  742. }
  743.  
  744. /*****************************************************************************/
  745.  
  746. void mib_set_eventhandlers(void *a, void *b, void *c)
  747. {
  748.   mib_events.mib_pick_mib_Widget = a;
  749.   mib_events.mib_move_mib_Widget = b;
  750.   mib_events.mib_unpick_mib_Widget = c;
  751. }
  752.  
  753. /*****************************************************************************/
  754.  
  755. void mib_apply_eventhandlers(Widget this, mib_Widget *actual)
  756. {
  757.   XtAddEventHandler(this, ButtonPressMask, FALSE,
  758.     mib_events.mib_pick_mib_Widget, (XtPointer)actual);
  759.   XtAddEventHandler(this, Button3MotionMask, FALSE,
  760.     mib_events.mib_move_mib_Widget, (XtPointer)actual);
  761.   XtAddEventHandler(this, ButtonReleaseMask, FALSE,
  762.     mib_events.mib_unpick_mib_Widget, (XtPointer)actual);
  763.  
  764. }
  765.  
  766. /*****************************************************************************/
  767.